/*
 *  snapshot_helper.cpp
 *  Wilson
 *
 *  Created by Sebastian Orfino on 11/18/11.
 *  Copyright 2011 lbs3. All rights reserved.
 *
 */

#include "VCPlugInHeaders.h"

#include "snapshot_helper.h"

#include "boost/shared_ptr.hpp"
#include "Base64MemoryXferBytes.h"
#include "IPMStream.h"
#include "StreamUtil.h"
#include "IPathGeometry.h"
#include "SnapshotUtilsEx.h"
#include "ISpread.h"
#include "IPasteboardUtils.h"

using namespace wilson;

std::string snapshot_helper::shoot(const PMRect& clippingBounds) const 
{
	
	do {
		
		if (!tablero_) break;
		
		//ahora genero la mini imagen de la nota.
		boost::shared_ptr<SnapshotUtilsEx> snapshot( new SnapshotUtilsEx(clippingBounds,
												   PMMatrix(),
												   tablero_,
												   1.0, //xScaleFactor
												   1.0, //yScaleFactor
												   72.0, //res
												   72.0, //min res
												   10.0, //bleed
												   SnapshotUtilsEx::kCsRGB,
												   kTrue //add transparency alpha
												   )
							  );
		
		// We have to call Draw on the snapshot
		if( snapshot->Draw(IShape::kPreviewMode | IShape::kPrinting) != kSuccess )
			break;

		Base64MemoryXferBytes buffer;
		InterfacePtr<IPMStream> base64Stream(StreamUtil::CreateMemoryStreamWrite(&buffer));
		
		if (!base64Stream) break;
		
		ErrorCode err = snapshot->ExportImageToPNG(base64Stream);
		if (err != kSuccess) break;
		
		return buffer.GetBuffer();	
		
		
	} while(kFalse);
	
	return "";
	

}